package com.itheima.authority;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.RedisConstant;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import redis.clients.jedis.JedisPool;

import java.util.ArrayList;
import java.util.List;

public class UserDetailsServiceImpl implements UserDetailsService {
    @Reference
    UserService userService;
    @Autowired
    JedisPool jedisPool;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        String code = jedisPool.getResource().get(username + RedisConstant.Validate_Code_Login);
        List<GrantedAuthority> list=new ArrayList<>();
        list.add(new SimpleGrantedAuthority("Role_Member"));
        return new User(username,"{noop}"+code,list);
    }
}
